package com.yx.cloud.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yx.cloud.R;
import com.yx.cloud.bean.CountryCodeBean;

import java.util.List;

/**
 * Created by Administrator on 2018/12/30.
 */

public class CountryCodeAdapter extends BaseAdapter {
    Context mContext;
    List<CountryCodeBean> mList;

    public CountryCodeAdapter(Context context, List list) {
        mContext = context;
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CountryCodeAdapter.ViewHolder mHolder ;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.countrycodelist_item, null);
            mHolder = new CountryCodeAdapter.ViewHolder();
            mHolder.mName = convertView.findViewById(R.id.tv_countrycode_name);
            mHolder.mCode = convertView.findViewById(R.id.tv_countrycode);
            convertView.setTag(mHolder);
        }else {
            mHolder = (CountryCodeAdapter.ViewHolder) convertView.getTag();
        }

        CountryCodeBean bean = mList.get(position);
        mHolder.mName.setText(bean.getName());
        mHolder.mCode.setText("+" + String.valueOf(bean.getCode()));
        return convertView;
    }

    class ViewHolder {
        TextView mName;
        TextView mCode;
    }
}
